package com.yang.yangListener;

import com.yang.YangCuiLian;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.List;

public class YangEntityDamageListener implements Listener {
    private YangCuiLian yangCuiLian;
    public YangEntityDamageListener(YangCuiLian yangCuiLian) {
        this.yangCuiLian = yangCuiLian;
    }

    @EventHandler
    public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
        // 获取武器的属性
        Entity damager = event.getDamager();
        Entity damaged = event.getEntity();
        Player player = (Player) damager;
        LivingEntity target = (LivingEntity) damaged;

        // 获取玩家手持的武器
        ItemStack weapon = player.getInventory().getItemInMainHand();
        ItemMeta itemMeta = weapon.getItemMeta();
        List<String> lore = itemMeta.getLore();
        for (String item : lore){
            yangCuiLian.getLogger().info(item);
        }
    }
}
